#include "qtreversi.h"

QTReversi::QTReversi(QWidget *parent) :
	QWidget(parent) {
	/*GameBoardModelTests t1;
	 QTest::qExec(&t1);*/

	uiMain.setupUi(this);

	QStackedLayout *mainLayout = new QStackedLayout(this);
	//mainLayout->setStackingMode(QStackedLayout::StackAll);

	WindowMainMenu *wMainMenu = new WindowMainMenu(this);
	int iMain = mainLayout->addWidget(wMainMenu);

	QWidget *widget = new QWidget(this);
	uiOptions.setupUi(widget);
	mainLayout->addWidget(widget);

	WindowGame *wGame = new WindowGame(this);
	int iGame = mainLayout->addWidget(wGame);

	WindowAbout *wAbout = new WindowAbout(this);
	int iAbout = mainLayout->addWidget(wAbout);

	QStateMachine *machine = new QStateMachine(this);

	stateStart = new QState(machine);
	stateAbout = new QState(machine);
	stateGame = new QState(machine);
	finalState = new QFinalState(machine);

	wGame->setStateMachine(stateGame);

	stateStart->assignProperty(mainLayout, "currentIndex", iMain);
	stateStart->addTransition(wMainMenu, SIGNAL(exitProgram()), finalState);
	QObject::connect(machine, SIGNAL(finished()), QApplication::instance(),
			SLOT(quit()));

	stateStart->addTransition(wMainMenu, SIGNAL(openAbout()), stateAbout);
	stateAbout->assignProperty(mainLayout, "currentIndex", iAbout);
	stateAbout->addTransition(wAbout, SIGNAL(closed()), stateStart);

	stateStart->addTransition(wMainMenu, SIGNAL(startGame()), stateGame);
	stateGame->assignProperty(mainLayout, "currentIndex", iGame);
	//stateGame->addTransition(wAbout ,  SIGNAL(closed()) ,  stateStart);

	machine->setInitialState(stateStart);
	machine->start();

	/*QVector<int> xx;
	xx << 0<<8<<16<<24<<32<<40<<48<<56;
	quint64 t = 0;
	for (int i = 0; i < xx.count(); i++) {
		t += (quint64) 1 << xx[i];
	}
	qDebug() << t;*/
/*	quint64 t = 0x1000;
	int tt = 8;
	qDebug() << (t >> tt);*/
	//qDebug() << -1%8;
}

QTReversi::~QTReversi() {

}
